package com.dakor.catalog.gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * Main menubar.
 *
 * @author Korobeynikov Dmitry
 * @version 1.0
 */
public class MenuBar extends JMenuBar {
    /** the messages's provider */
    private static final ResourceBundle msgs =
            ResourceBundle.getBundle("i18n/MenuBarMessages", new Locale("ru", "RU"));

    private Window owner;

    public MenuBar(final Window owner) {
        this.owner = owner;

        add(createTotalMenu());
    }

    private JMenu createTotalMenu() {
        JMenu menu = new JMenu(msgs.getString("totalMenu"));

        JMenuItem menuItem = new JMenuItem(msgs.getString("refreshMenuItem"), KeyEvent.VK_R);
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(owner, msgs.getString("infDialog"), msgs.getString("titleInfDialog"),
                        JOptionPane.INFORMATION_MESSAGE);
            }
        });
        menu.add(menuItem);

        menu.addSeparator();

        menuItem = new JMenuItem(msgs.getString("exitMenuItem"), KeyEvent.VK_Q);
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                owner.dispose();
            }
        });
        menu.add(menuItem);

        return  menu;
    }

}
